<template>
	<div class="prepare-list-box">
		<ul class="clear"  v-loading="loading"  element-loading-text="拼命加载中">
			<li class="prepare-list" v-for="item of prepareLis">
				<div class="prepare-list-h clear">
					<router-link :to="{path: '/prepare/see',query: {id:item.prepareid, name: item.prepare_name}}">{{item.prepare_name}}</router-link>
					<el-popover
						placement="bottom"
						width="120"
						popper-class="prepare"
						trigger="hover">
						<ul class="prepare-op">
							<li><router-link :to="{path: '/prepare/edit',query: {id:item.prepareid, name: item.prepare_name,type: 1}}">编辑</router-link></li>
							<!-- <li>
								<router-link to=''>上传教案</router-link>
							</li> -->
							<li @click="removeLsit(item.prepareid)">删除备课</li>
						</ul>
						<i slot="reference" class="el-icon-arrow-down"></i>
					</el-popover>
				</div>
				<!--  -->
				<ul class="prepare-tag clear">
					<li>{{item.gradename}}</li>
					<li>{{item.subjectname}}</li>
				</ul>

				<div class="prepare-set clear">
					<router-link :to="{path: '/prepare/task',query: {id: item.prepareid, name: item.prepare_name}}">任务<i>（{{item.task_count}}）</i></router-link>
					<router-link :to="{path: '/prepare/resource',query: {id: item.prepareid, name: item.prepare_name}}">资源<i>（{{item.resource_count}}）</i></router-link>
					<router-link :to="{path: '/prepare/video', query: {id: item.prepareid, name: item.prepare_name}}">视频<i>（{{item.video_count}}）</i></router-link>
					<router-link :to="{path: '/prepare/test', query: {id: item.prepareid, name: item.prepare_name}}">试卷<i>（{{item.test_count}}）</i></router-link>
					<el-tooltip :content="item.profile" placement="top" effect="light">
					  <el-button>备课目标</el-button>
					</el-tooltip>
				</div>
			</li>
		</ul>

		<el-pagination class="pageing"
			v-if="total_sum > page_size"
			@current-change="SizeChange"
			:current-page="page_index"
			:page-size="page_size"
			layout="total, prev, pager, next, jumper"
			:total="total_sum">
		</el-pagination>
		<!--  -->
		<div class="dependent" v-if="placeholder">
			<i class="ipng image_state01"></i>
			<p>还没发现任何相关的内容哦~</p>
		</div>
	</div>
</template>

<script>
	
	export default {
		data(){
			return {
				placeholder: false,
				page_size: this.$g.page_size,
				page_index: 1,
				total_sum: 0,
				prepareLis: [],
				loading: true,
			}
		},
		created(){
			this.get_prepare()
		},
		methods: {
			get_prepare(){
				let success = (res =>{
					this.prepareLis = res.data.data;
					this.total_sum = parseInt(res.data.data_sum)

					this.loading = false;
					this.prepareLis.length === 0
					? this.placeholder = true
					: this.placeholder = false
				});

				this.$ajax({
					url: 'api/prepare/prepare_list',
					method: 'get',
					params: {
						type: 1,
						userid: this.$g.user_id,
						page_index: this.page_index,
						page_size: this.page_size
					},
					func: {success: success}
				})
			},
			removeLsit(id) {
				this.$confirm('你确定要删除吗？', '删除', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					customClass: 'removeing'
				}).then(() => {
					let success = ( res=>{
						this.$message.success(res.msg)
						this.get_prepare()
					});
					this.$ajax({
						url: 'api/prepare/prepare',
						method: 'delete',
						params: {
							prepareid: id,
							type: 0,
							create_id: this.$g.user_id
						},
						func: {success: success}
					})
				}).catch(() => {});
			},
			SizeChange(val) {
				// console.log(`每页 ${val} 条`);
				this.page_index = val
				this.get_prepare()
			}
		}
	}
</script>